<template>
  <div :class="className" :style="{ height: height, width: width}" :id="chartOption.bindingDiv">
    <dv-decoration-5 :key="key" :color="color" :dur="dataOption.dur"></dv-decoration-5>
  </div>
</template>

<script>
import echarts from "echarts";
require("echarts/theme/macarons"); // echarts theme
import resize from '@/views/dashboard/mixins/resize'

import '../../animate/animate.css'

const animationDuration = 6000;

export default {
  props: {
    className: {
      type: String,
      default: "chart",
    },
    width: {
      type: String,
      default: "100%",
    },
    height: {
      type: String,
      default: "100%",
    },
    chartOption: {
      type: Object,
    },
  },
  data() {
    return {
      chart: null,
      dataOption: this.chartOption,
      key: 1
    };
  },
  watch: {
    width() {
      this.initChart();
    },
    height() {
      this.initChart();
    },
    chartOption: {
      deep: true,
      handler(newVal) {
        this.setOptions(JSON.parse(JSON.stringify(newVal)));
      }
    },

  },
  mounted() {
    this.$nextTick(() => {
      this.initChart();
    });
  },
  beforeDestroy() {
    if (!this.chart) {
      return;
    }
    this.chart = null;
  },
  computed:{
    color(){
      let corlorArr = [];
      corlorArr.push(this.dataOption.color1);
      corlorArr.push(this.dataOption.color2);
      return corlorArr
    }
  },
  methods: {
    initChart() {
      
      this.setOptions(this.chartOption);
      
    },
    setOptions: async function(dataOption) {
      
      this.key = Math.random();
    },
   
  }
};
</script>
